Skip to content

perf: eliminate redundant read_dispair calls in try_into_call#2793

Open
thedavidmeister wants to merge 3 commits into
mainfrom
2026-06-29-issue-2776-dispair-cache
Open

perf: eliminate redundant read_dispair calls in try_into_call#2793
thedavidmeister wants to merge 3 commits into
mainfrom
2026-06-29-issue-2776-dispair-cache

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

try_into_call previously called read_dispair three times — once inline and once inside each try_parse_rainlang call — totalling 12 sequential RPC round-trips just to read 4 immutable deployer addresses. At 300ms RTT (remote RPC) that is ~3.6s of avoidable latency.

Changes

  • Add parse_bytecode_with_dispair: the parsing body extracted from try_parse_rainlang, takes a pre-fetched DISPaiR (no additional dispair reads).
  • try_parse_rainlang is now a thin wrapper: read_dispair + parse_bytecode_with_dispair. All existing tests remain unchanged.
  • try_into_call calls read_dispair once, clones for the first parse, moves for the second parse, and extracts interpreter/store upfront.

Result

RPC calls per generate_deposit_and_add_order_calldatas (dispair portion):

Before After
12 (3× read_dispair) 4 (1× read_dispair)

Total for a single deposit+addOrder: 14 → 6 sequential eth_call round-trips, saving ~2.4s at 300ms RTT.

Test

Adds assertions to test_into_add_order_call verifying both config.evaluable.interpreter/store and tasks[0].evaluable.interpreter/store match the expected interpreter/store addresses (and match each other). This mutation-validates that both evaluables receive the correct dispair from the single shared read.

Closes #2776

Co-Authored-By: Claude noreply@anthropic.com

Summary by CodeRabbit

  • Bug Fixes
    • Reduced unnecessary network calls when preparing orders, which should make order creation faster and more reliable.
    • Ensured both the main order logic and follow-up action use the same resolved interpreter and store values.

try_into_call previously called read_dispair 3 times (once directly and
once inside each try_parse_rainlang call), totalling 12 sequential RPC
round-trips just to read 4 immutable deployer addresses.

Add parse_bytecode_with_dispair, which takes a pre-fetched DISPaiR and
skips the read_dispair step. try_parse_rainlang becomes a wrapper around
read_dispair + parse_bytecode_with_dispair. try_into_call now calls
read_dispair once and passes the result to both parse calls via clone/move.

RPC calls for a single deposit+addOrder submission: 14 → 6 (saves 8
sequential round-trips, ~2.4s at 300ms RTT).

Adds assertions to test_into_add_order_call verifying both config.evaluable
and tasks[0].evaluable carry the correct interpreter and store addresses
from the single shared dispair read.

Closes #2776

Co-Authored-By: Claude <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: adf828b6-3fe4-4451-ae23-82967ad4a505

📥 Commits

Reviewing files that changed from the base of the PR and between b1de534 and e4ca835.

📒 Files selected for processing (1)
  • crates/common/src/add_order.rs

📝 Walkthrough

Walkthrough

The rainlang parsing flow in AddOrderArgs is refactored to eliminate redundant DISPaiR RPC calls. A new parse_bytecode_with_dispair method accepts a pre-fetched DISPaiR instance, and try_into_call now fetches DISPaiR once, reusing cached interpreter and store values for both main and post-task evaluables.

Changes

DISPaiR reuse in rainlang parsing

Layer / File(s) Summary
Extract parse_bytecode_with_dispair
crates/common/src/add_order.rs
New public async method accepts a pre-fetched DISPaiR and parses rainlang into bytecode; test-only try_parse_rainlang now reads dispair and delegates to it.
Single dispair fetch in try_into_call
crates/common/src/add_order.rs
read_dispair is called once at the start, caching interpreter and store; both main and post-task rainlang parsing reuse the shared dispair, and both evaluable structures use the cached values instead of separate fetches.
Test assertions for shared addresses
crates/common/src/add_order.rs
New test assertions verify config.evaluable and tasks[0].evaluable use identical interpreter and store addresses from the single shared fetch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Related issues: Addresses redundant read_dispair RPC round-trips described in "RaindexOrderBuilder: sequential RPC round-trips inflate order prep."

Suggested reviewers: rainlanguage core maintainers familiar with add_order.rs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific and accurately summarizes the main performance refactor in try_into_call.
Linked Issues check ✅ Passed The PR implements the core #2776 fix by reusing a pre-fetched DISPair and removing redundant read_dispair calls.
Out of Scope Changes check ✅ Passed The changes stay focused on the RPC reduction refactor and corresponding tests, with no unrelated scope visible.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-29-issue-2776-dispair-cache

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

thedavidmeister and others added 2 commits June 29, 2026 17:49
Mark try_parse_rainlang as #[cfg(test)] — after the try_into_call
refactor it is only called from tests, so the production build flags
it as dead code under -D warnings.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RaindexOrderBuilder: sequential RPC round-trips inflate order prep

1 participant